<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__ROOT__/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="__ROOT__/layui/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            {{#  if((d.state == 2)){ }}
            <a class="layui-btn layui-btn-green layui-btn-xs data-count-advance"  >已联系</a>
            {{#  } else { }}
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-advance" attr-id="{{d.id}}" lay-event="advance">待联系</a>
            {{#  } }}

        </script>

    </div>
</div>
<script src="__ROOT__/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/index.php/index/developer/get_phone',

            cols: [[
                {field: 'id',  title: '编号', sort: true},
                {field: 'phone',  title: '电话', sort: true},
                {field: 'uptime',  title: '留电话时间', sort: true},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 20,
            page: true,

        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {

            var result = JSON.stringify(data.field);

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */


        table.on('tool(currentTableFilter)', function (obj) {
            var mdata = obj.data;
            if (obj.event === 'advance') {

                var id = $(this).attr('attr-id');
                var url ="{:url('developer/yes_phone')}" ;
                data = {};
                data['id']=id;

                layer.open({
                    type :0,
                    title:'确认已联系?',
                    btn:['是','否'],
                    icon:3,
                    closeBtn:2,
                    content:"是否确定已联系",
                    scrollbar:true,
                    yes:function () {
                        //执行跳转
                        todelete(url,data);
                    }
                });
            }
        });

        function todelete(url,data) {
            var success = "{:url('developer/phone')}";
            $.post(
                url,
                data,
                function (s) {
                    if(s.status ==1){
                        layer.open({
                            content:s.message,
                            icon:1,
                            yes : function(){
                                location.href=success;
                            }
                        });
                    }else{
                        layer.open({
                            content:s.message,
                            icon:2,
                            title : '错误提示'
                        });
                    }
                }
                ,'JSON');

        }

    });
</script>

</body>
</html>